<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
JsWs Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="response.js Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b>JsWs</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>response.js</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		No overview generated for 'response.js'<BR/><BR/>
	
</p>

<hr>


    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
    <td colspan=2><font size="+2">
    
        <b>Class Summary</b>
    
    </font></td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="ExResponseEnd.html">ExResponseEnd</a></b></td>
    <td>Exception used to signal the end of processing for a request
 </td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="Response.html">Response</a></b></td>
    <td>Class to represent an HTTP response
 </td>
    </tr>
    
    </table>
    <hr/> 


<!-- ========== METHOD SUMMARY =========== -->

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"><span class="comment">/* ***** BEGIN LICENSE BLOCK *****
 *   Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is JsWs.
 *
 * The Initial Developer of the Original Code is
 * Chris Winberry.
 * Portions created by the Initial Developer are Copyright (C) 2007
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 * 
 * ***** END LICENSE BLOCK ***** */</span>


<span class="comment">/**
 * <span class="attrib">@class</span> Exception used to signal the end of processing for a request
 * <span class="attrib">@constructor</span>
 * <span class="attrib">@base</span> ExBase
 * <span class="attrib">@param</span> {String} msg Description of exception
 * <span class="attrib">@param</span> {Number} code (optional) Error code
 * <span class="attrib">@param</span> {Exception} ex (optional) An earlier exception to wrap
 * <span class="attrib">@see</span> Response#end
 */</span>
<span class="reserved">function</span> ExResponseEnd (msg, code, ex) { ExResponseEnd.baseConstructor.call(<span class="reserved">this</span>, msg, code, ex); }
SubClass(ExBase, ExResponseEnd);


<span class="comment">/**
 * <span class="attrib">@class</span> Class to represent an HTTP response
 * <span class="attrib">@constructor</span>
 */</span>
<span class="reserved">function</span> Response (handlerObj) {
	<span class="comment">/** <span class="attrib">@private</span> */</span>
	<span class="reserved">this</span>.handlerObj = handlerObj;
	<span class="comment">/**
	 * Flag to indicate whether output should be buffered or sent immediately
	 * <span class="attrib">@type</span> Boolean
	 */</span>
	<span class="reserved">this</span>.buffer = true;
	<span class="comment">/** <span class="attrib">@private</span> */</span>
	<span class="reserved">this</span>.headersSent = false;
	<span class="comment">/** <span class="attrib">@private</span> */</span>
	<span class="reserved">this</span>.output = new Array();
	<span class="comment">/**
	 * HTTP status code
	 * <span class="attrib">@type</span> Number
	 */</span>
	<span class="reserved">this</span>.status = 200;
	<span class="comment">/**
	 * Headers collection
	 * <span class="attrib">@type</span> Hash
	 */</span>
	<span class="reserved">this</span>.headers = new Array();
	<span class="comment">/**
	 * Cookies collection
	 * <span class="attrib">@type</span> Cookie[]
	 */</span>
	<span class="reserved">this</span>.cookies = new Array();

	<span class="reserved">this</span>.contentType(<span class="literal">"text/html"</span>);
}


<span class="comment">/**
 * Write data to output (client)
 * <span class="attrib">@param</span> {String} data Data to write
 */</span>
Response.<span class="reserved">prototype</span>.write = <span class="reserved">function</span> (data) {
	<span class="reserved">if</span> (<span class="reserved">this</span>.buffer) {
		<span class="reserved">this</span>.output[<span class="reserved">this</span>.output.length] = data;
	} <span class="reserved">else</span> {
		<span class="reserved">this</span>.handlerObj.write(<span class="reserved">this</span>.renderHeaders());
		<span class="reserved">this</span>.handlerObj.write(data);
	}
}


<span class="comment">/**
 * Writes any buffered data to output (client)
 */</span>
Response.<span class="reserved">prototype</span>.flush = <span class="reserved">function</span> () {
	<span class="reserved">this</span>.handlerObj.write(<span class="reserved">this</span>.renderHeaders());
	<span class="reserved">if</span> (<span class="reserved">this</span>.output.length)
		<span class="reserved">this</span>.handlerObj.write(<span class="reserved">this</span>.output.join(<span class="literal">''</span>)); <span class="reserved">this</span>.output = new Array();
	<span class="comment">//this.buffer = false; // ???</span>
}


<span class="comment">/**
 * Removes any buffered output
 */</span>
Response.<span class="reserved">prototype</span>.clear = <span class="reserved">function</span> () {
	<span class="reserved">this</span>.output = new Array();
}


<span class="comment">/**
 * Immediately halts execution of the current page. Any buffered content
 * 	is flushed.
 * <span class="attrib">@exception</span> ExResponseEnd
 */</span>
Response.<span class="reserved">prototype</span>.end = <span class="reserved">function</span> () {
	<span class="reserved">if</span> (<span class="reserved">this</span>.buffer) {
		<span class="reserved">this</span>.headers[<span class="literal">"Content-Length"</span>] = <span class="reserved">this</span>.output.join(<span class="literal">''</span>).length;
	}
	<span class="reserved">this</span>.flush();
	throw(new ExResponseEnd());
}


<span class="comment">/**
 * Sets the content-type header of the response
 * <span class="attrib">@param</span> {String} type MIME type
 */</span>
Response.<span class="reserved">prototype</span>.contentType = <span class="reserved">function</span> (type) {
	<span class="reserved">this</span>.headers[<span class="literal">"Content-Type"</span>] = type;
}


<span class="comment">/**
 * Causes the response to issue a redirect to the client.
 * <span class="attrib">@param</span> {String} location URL to redirect to. Passing a null
 *  clears the redirect
 */</span>
Response.<span class="reserved">prototype</span>.redirect = <span class="reserved">function</span> (location) {
	<span class="reserved">if</span> (location != null) {
		<span class="reserved">this</span>.headers[<span class="literal">"Location"</span>] = location;
		<span class="reserved">this</span>.status = 302;
	} <span class="reserved">else</span> {
		delete <span class="reserved">this</span>.headers[<span class="literal">"Location"</span>]; <span class="comment">// ???</span>
		<span class="reserved">this</span>.status = 200; <span class="comment">// ???</span>
	}
}


<span class="comment">/**
 * Adds a cookie to the response
 * <span class="attrib">@param</span> {Cookie} cookie Cookie to add
 */</span>
Response.<span class="reserved">prototype</span>.setCookie = <span class="reserved">function</span> (cookie) {
	<span class="reserved">this</span>.cookies[cookie.name] = cookie;
}


<span class="comment">/** <span class="attrib">@private</span> */</span>
Response.<span class="reserved">prototype</span>.statText = {
	200: <span class="literal">"OK"</span>,
	301: <span class="literal">"Moved Permanently"</span>,
	302: <span class="literal">"Found"</span>,
	304: <span class="literal">"Not Modified"</span>,
	400: <span class="literal">"Bad Request"</span>,
	401: <span class="literal">"Unauthorized"</span>,
	403: <span class="literal">"Forbidden"</span>,
	404: <span class="literal">"Not Found"</span>,
	405: <span class="literal">"Method Not Allowed"</span>,
	500: <span class="literal">"Internal Server Error"</span>,
	501: <span class="literal">"Not Implemented"</span>,
	503: <span class="literal">"Service Unavailable"</span>,
	505: <span class="literal">"HTTP Version Not Supported"</span>
};

<span class="comment">/** <span class="attrib">@private</span> */</span>
Response.<span class="reserved">prototype</span>.renderStatus = <span class="reserved">function</span> () {
	<span class="reserved">return</span>(<span class="literal">"HTTP/1.1 "</span> + <span class="reserved">this</span>.status + <span class="literal">" "</span> + ((<span class="reserved">this</span>.statText[<span class="reserved">this</span>.status] == null) ? <span class="literal">"UNKNOWN"</span> : <span class="reserved">this</span>.statText[<span class="reserved">this</span>.status]) + <span class="literal">"\r\n"</span>);
}


<span class="comment">/** <span class="attrib">@private</span> */</span>
Response.<span class="reserved">prototype</span>.renderHeaders = <span class="reserved">function</span> () {
	<span class="reserved">if</span> (<span class="reserved">this</span>.headersSent) { <span class="reserved">return</span>(<span class="literal">""</span>); }
	<span class="reserved">this</span>.headersSent = true;
	var sRetval = <span class="reserved">this</span>.renderStatus();
	<span class="reserved">for</span> (var key in <span class="reserved">this</span>.headers)
		sRetval += key + <span class="literal">": "</span> + <span class="reserved">this</span>.headers[key] + <span class="literal">"\r\n"</span>;
	<span class="reserved">for</span> (var key in <span class="reserved">this</span>.cookies)
		sRetval += <span class="reserved">this</span>.cookies[key] + <span class="literal">"\r\n"</span>;
	<span class="reserved">return</span>(sRetval + <span class="literal">"\r\n"</span>);
}


<span class="comment">/**
 * Runs cleanup on internal objects
 */</span>
Response.<span class="reserved">prototype</span>.destroy = <span class="reserved">function</span> () {
	<span class="reserved">this</span>.handlerObj.destroy();
	<span class="reserved">this</span>.handlerObj = null;
	<span class="reserved">this</span>.output = null;
	<span class="reserved">this</span>.headers = null;
	<span class="reserved">for</span> (var i = 0; i &lt; <span class="reserved">this</span>.cookies.length; i++) {
		<span class="reserved">this</span>.cookies[i].destroy();
		<span class="reserved">this</span>.cookies[i] = null;
	}
	<span class="reserved">this</span>.cookies = null;
	<span class="reserved">this</span>.contentType = null;
}

</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b>JsWs</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Thu Nov  8 22:50:16 2007</div>
</body>
</html>
